import 'package:flutter/material.dart';
import 'package:sz/tools/tools.dart';
import 'package:webview_flutter/webview_flutter.dart';

// webview
class WebviewPage extends StatefulWidget {
  const WebviewPage({Key? key, required this.config}) : super(key: key);
  final WebConfig config;

  @override
  WebviewPgesState createState() => WebviewPgesState();
}

class WebviewPgesState extends State<WebviewPage> {
  late WebViewController webViewController;

  @override
  void initState() {
    webViewController = WebViewController()
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..loadRequest(Uri.parse(widget.config.url));
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: widget.config.title != ""
          ? AppBar(
              title: Text(
                'view',
                style: TextStyle(
                  fontSize: setSp(32),
                ),
              ),
            )
          : null,
      body: WebViewWidget(controller: webViewController),
    );
  }
}

class WebConfig {
  late final String url;
  late final String title;
  Map<String, dynamic>? query; //传递过来的参数

  WebConfig({required this.url, this.title = '', this.query});
}
